<!-- 搜索结果 -->
<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="(item, index) in list"
        :key="index"
        :title="item.title"
      />
    </van-list>
  </div>
</template>

<script>
import { getSearchResult } from "../../../api/search";
export default {
  name: "SearchResult",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      per_page: 20,
    };
  },
  props: ["searchVal"],
  methods: {
    async onLoad() {
      // 获取搜索结果
      let { data } = await getSearchResult({
        page: this.page,
        per_page: this.per_page,
        q: this.searchVal,
      });
      let result = data.data.results;
      this.list.push(...result);
      this.loading = false;
      if (result.length) this.page++;
      else this.finished = true;
    },
  },
};
</script>
<style lang= "less" scoped>
</style>